import paho.mqtt.client as mqtt
from time import sleep
import json

while True:
    num = int(input("请选择1(C16)2(其它MQTT设备)："))
    sn = str(input('请输入要推送的sn：'))
    content = str(input("请输入要推送的内容(upgrade/unbind/log/cleancache)："))
    contents = {
        "cmd": content
    }
    client = mqtt.Client()
    client.username_pw_set('CMAC692000004957REP8YnS', 'ji6LeXKg')
    client.connect('so2.airphone.vip', 1883, 5)
    if num == 1:
        topic = '/iot/cmd/' + sn
        client.publish('/iot/cmd/' + sn, payload=f'{json.dumps(contents)}', qos=0)
        print('推送成功！')
        client.loop_forever()
        break
    elif num == 2:
        client.publish('/1007/' + sn + '/user/iot/cmd', payload=f'{contents}', qos=0)
        print('推送成功！')
        client.loop_forever()
        break
    else:
        print("输入错误！")
        continue
